;; The first three lines of this file were inserted by DrRacket. They record metadata
;; about the language level of this file in a form that our tools can easily process.
#reader(lib "htdp-advanced-reader.ss" "lang")((modname hwk4) (read-case-sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-decimal #t #t none #f ())))
#|
    L.I.S.P.: Lots of irritating and silly parentesis
    Homework 4

    Author:
       Henrique "Nican" Polido
       Keleigh O'Neil
|#


#|
|- Exam is composed of a list of actions and a description string:
  |- Sections, that has a list of triggers, that can be
  |  |- Asking a question
  |  |   |- Has one, or a list of, correct answers
  |  |   |- Has a maximun number of attempts, 0 for no limit
  |  |- Conditional triggers
  |  |   |- One lambda condition, with input of a struct that has how many questions are correct
  |  |   |  and how many questions are wrong
  |  |   |  |- If it returns true, it will call one list of new triggers
  |  |   |  |- If returns false, can execute another function of triggers
  |  |- Displaying current statistics on the current section
  |  |- Skip the next X items in the list of triggers
  |  |- Display a message
  |- A command to display the current statistics of all already taken secitons
  |- Display a message
|#


;; an Exam is a (make-exam string list[actions])  
;; An exam will be given to the students, and follow the list of actions in order
(define-struct exam(summary loa))

;;A action can be a:
;; - display-stats-all 
;; - message
;; - section 

;;A display-stats-all is a (make-display-stats-all)
;;Displays the current stats of all parts already taken of the exam
(define-struct display-stats-all ())

;; a section is a (make-section list[trigger] string)  
;;A section that has a list of triggers and a overall summary to be printed in the beggining
(define-struct section(lot summary))

;; a message is a (make-message string)
;;Prints the output string to the output window
(define-struct message (output))

;;A trigger can be a:
;; -question
;; -question-with-hint
;; -cond-trigger
;; -message
;; -skip
;; -display-stats

;; a question is (make-question string ans limit)
;;Ans can be:
;; -String
;; -List of strings, which any can be the answer
;;The limit is the maximun number of attempts, 0 for no limit
(define-struct question (question answer limit))

;; a question-with-hint is (make-question-with-hint string string ans limit)
;;Ans can be:
;; -String
;; -List of strings, which any can be the answer
;;The limit is the maximun number of attempts, 0 for no limit
;;The hint will only be given to the student if he asks for it
(define-struct question-with-hint (question hint answer limit))

;; a cond-trigger is a (make-cond-trigger (secetion-stats->boolean) list[trigger] list[trigger])
;;A conditonal trigger, depended on the output, it can execute the first list, or the second list
(define-struct cond-trigger (condition true-list false-list))

;;A section-stats is a (number number number)
;;A structure that keeps how well the student is doing
;;Keeps: # of correct, #of incorrect, #of questions
(define-struct section-stats (correct incorrect count))

;;A skip is a (number)
;;Skip the next X amount of triggers
(define-struct skip (count))

;;A display-stats is a (make-display-stats)
;;Displays how many questions the student got right and wrong in the current sectuin
(define-struct display-stats ())


#| ;;;;;;;;;;;;;;;;;;;;;;;;
    Sample exams
;;;;;;;;;;;;;;;;;;;;;; |#


(define math-exam 
  (make-exam
   "Math exam" 
   (list
    (make-section 
     "Arithmetic Problems"
     (list
      (make-question
       "What is 3*4+2?"
       "14"
       1)
      (make-question
       "What is 2+3*4?"
       "14"
       1)
      (make-question
       "What is 5+2*6?"
       "18"
       1)
      (make-cond-trigger 
       (lambda (stats) (< (/ (section-stats-correct stats) (section-stats-count stats)) 0.5))
       (list
        (make-message "You seem to be having trouble with these.  Try again.")
        (make-question
         "What is 3+5*2"
         "13"
         1)
        )
       empty)
      (make-question 
       "What is the reduced form of 12/18?: (1) 6/9  (2) 1/1.5  (3) 2/3"
       "3"
       1)
      (make-question
       "What is 8+3*2?"
       "14"
       1)
      )
     )
    (make-display-stats-all)
    )
   )
  )


(define history-exam 
  (make-exam
   "History exam" 
   (list
    (make-section 
     "WPI HISTORY"
     (list
      (make-question
       "When was WPI founded?"
       "1865"
       1)
      (make-message "Let's see if you know your WPI personalities.")
      (make-question-with-hint
       "What is Gompei?"
       "Think bleating"
       "goat"
       1)
      (make-question
       "Who was the first president of WPI?: (1) Boynton  (2) Washburn  (3) Thompson"
       "3"
       1)
      (make-display-stats)
      (make-question
       "Name one of the two towers behind a WPI education"
       (list "boynton" "washburn")
       1)
      )
     )
    (make-display-stats-all)
    (make-message "There's more WPI history on the web.  And life.")
    )
   )
  )




